/**
 * @Title: ExampleFile.java
 * @Package com.example.package
 * @Description: Placeholder (briefly describe the purpose of this file)
 * @Author: Evan
 * @Date: 2023-08-18
 * @Version: V1.0
 *
 * Copyright Notice:
 * This project is released in open source and follows the applicable open source license.
 * All rights reserved. (c) 2023 Evan.
 * This project is protected by copyright laws and international copyright treaties.
 * Unauthorized reproduction, sale, copy, modification, merge, publication, distribution,
 * licensing, and/or sales of this software and its copies are prohibited without permission.
 * Please contact the author for authorization.
 * Contact Information:
 * @Email: uyevan@163.com
 */

package com.evan.biznak.vip.Util;

import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferencesUtils {
    /*存储器名称*/
    private static final String PREFS_NAME = "Data";
    /*Share 定义*/
    private static SharedPreferences.Editor editor;
    private static SharedPreferences editors;

    public static boolean checkString(Context context, String key) {
        editors = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); // 只对自己可见
        String value = editors.getString(key, null);
        return value != null && !value.isEmpty();
    }


    public static void saveString(Context context, String key, String value) {
        editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit(); // 只对自己可见
        editor.putString(key, value);
        editor.apply();
    }

    public static String getString(Context context, String key) {
        editors = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        return editors.getString(key, null);
    }

    public static void saveInt(Context context, String key, int value) {
        editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public static int getInt(Context context, String key) {
        editors = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        return editors.getInt(key, 0);
    }

    public static void clear(Context context) {
        editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.apply();
    }

    public static void clear(Context context, String key) {
        editor = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit();
        editor.remove(key); // 移除指定的 key
        editor.apply();
    }
}
